package com.myjava.list;

import java.util.ArrayList;
import java.util.ListIterator;



public class ArrayListdemo {

    static  ArrayList singString(ArrayList list){
        ArrayList n1 = new ArrayList();
        //2.遍历就数组
        ListIterator it = list.listIterator();
        while(it.hasNext()){
            Object o1 = it.next();
            //3.新数组的值与原数组的值进行比较是否包含

            if(!n1.contains(o1)){
                //4.如果不同就加入新数组

                n1.add(o1);
            }
        }
        //System.out.println(n1);
        return n1;
    }

    public static void main(String[] args) {
        ArrayList a1 = new ArrayList();
        a1.add("a");
        a1.add("a");
        a1.add("b");
        a1.add("b");
        a1.add("c");
        a1.add("d");
        a1.add("d");
        a1.add("f");
        a1.add("g");

        ArrayList sglist = singString(a1);
        System.out.println(sglist);
        ArrayList a2 = new ArrayList();
        a2.add("1");
        a2.add("1");
        a2.add("2");
        a2.add("3");
        a2.add("2");
        a2.add("4");
        ArrayList new2 = singString(a2);
        System.out.println(new2);

    /*
        //要求.去掉重复的字符
             // 1.创建一个新数组
        ArrayList n1 = new ArrayList();
        //2.遍历就数组
        ListIterator it = a1.listIterator();
        while(it.hasNext()){
            Object o1 = it.next();
            //3.新数组的值与原数组的值进行比较是否包含

            if(!n1.contains(o1)){
                //4.如果不同就加入新数组

                n1.add(o1);
            }
        }
        System.out.println(n1);

     */

    }

}
